<script setup lang="ts">
import {
  Container,
  ContainerStatus,
  Pod
} from "@/views/domain/kubeHud/api/k8s/types";
import { timeTrans } from "@/views/domain/kubeHud/utils";
import { IconPackage } from "@/views/domain/kubeHud/views/k8s/components/icons";

type Prop = {
  pod?: Pod;
  container?: Container;
  status?: ContainerStatus;
};

const props = defineProps<Prop>();
</script>

<template>
  <div class="pod-container-table-row-wrapper">
    <div class="pod-container-table-row">
      <div class="w-35">
        <div class="container-badge">
          <el-icon size="32"><IconPackage /></el-icon>
          <div
            :class="['badge', status.state?.running ? 'ready' : 'not-ready']"
          />
        </div>
      </div>
      <div class="flex flex-col items-start justify-start h-full text-start">
        <span class="row-content">{{ container?.name }}</span>
        <span class="row-title" size="small">
          创建时间: {{ timeTrans(status?.state?.running?.startedAt) }}
        </span>
      </div>

      <div class="flex flex-col justify-start h-full">
        <span class="row-content">
          {{ pod?.spec?.nodeName }} ( {{ pod?.status?.hostIP }})
        </span>
        <span class="row-title">节点</span>
      </div>

      <!-- 容器组ip -->
      <div class="flex flex-col justify-start h-full">
        <span class="row-content">{{ pod?.status?.podIP }}</span>
        <span class="row-title">容器组IP</span>
      </div>

      <!-- 重启次数 -->
      <div class="flex flex-col justify-start h-full">
        <span class="row-content">{{ status?.restartCount }}</span>
        <span class="row-title">重启次数</span>
      </div>
    </div>
  </div>
</template>
<style lang="scss">
.pod-container-table-row-wrapper {
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
  align-items: flex-start;
  width: 100%;
}
.pod-container-table-row {
  display: flex;
  flex-direction: row;
  justify-content: space-between;
  align-items: center;
  padding: 0.5rem;
  gap: 15px;

  font-size: 14px;
  color: var(--span-color-primary);

  &:hover {
    background-color: #f0f0f0;
  }
}

.row-title {
  font-size: 12px;
}

.row-content {
  font-size: 14px;
  font-weight: bold;
}

.container-badge {
  display: flex;
  position: relative;

  .badge {
    position: absolute;
    bottom: 0;
    right: 0px;
    width: 10px;
    height: 10px;
    border-radius: 50%;
  }

  .ready {
    background-color: var(--el-color-success);
  }

  .not-ready {
    background-color: var(--el-color-danger);
    animation: blink-and-change-color 2s infinite ease-in-out;
  }

  @keyframes blink-and-change-color {
    /* 动画开始时的状态，文字完全显示，颜色为红色 */
    0% {
      opacity: 1;
      background-color: var(--el-color-danger);
    }
    /* 动画进行到50%时的状态，文字完全隐藏，颜色为蓝色 */
    50% {
      opacity: 0.5;
      background-color: var(--el-color-danger);
    }
    /* 动画结束时的状态，文字完全显示，颜色为红色 */
    100% {
      opacity: 1;
      background-color: var(--el-color-danger);
    }
  }
}
</style>
